package controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import client.CcrmApp;
import model.Envelope;
import view.StartCampignGui;
/**
 * active campaign
 * @author moran
 *
 */
public class StartCampignController extends AbstractTransfer {
	/**
	 * back to menu 
	 */
	private MarketingManagController backCon = null;
	
	private StartCampignController currCon = null;
	
	private StartCampignGui currGUI = null;
	/**
	 * constructor
	 * @param M->MarketingManagController
	 * @param G->StartCampignGui
	 */
	public StartCampignController(MarketingManagController M,StartCampignGui G)
	{
		currCon = this ;
		currGUI = G;
		backCon = M;
		initBox();
		currGUI.addStartbtnAC(new ActiveCAC());
		currGUI.addMENUbtnAC(new BackMang());
	}
	/**
	 * give u all the campign who not active
	 */
	public void initBox()
	{
		Envelope ev = new Envelope("","take all unactive campign");
		CcrmApp.clien.setCurrObj(currCon);
		sendToServer(ev);
	}
	/**
	 * add item for combo box 
	 * @param s
	 */
	public void handleFormDBfirst(String s)
	{
		 String[] q=s.trim().split(",");
		 for (int i = 0 ; i< q.length;i++)
		 {
			 currGUI.getItemBOx().addItem(q[i]);
		 }
	}
	public void handleFormDBsecond(String msg)
	{
		 currGUI.getItemBOx().removeAllItems();
		currGUI.getLblwarning().setText("Sales operation initiated");
		 initBox();
	}
	
	
	class BackMang implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			currGUI.dispose();
			backCon.getMarkManGui().setVisible(true);			
		}
		

	}
	/**
	 * active the campain you choose
	 * @author liran
	 *
	 */
	class ActiveCAC implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			String itemC = new String();
			CcrmApp.clien.setCurrObj(currCon);
			itemC = currGUI.getSeclectCampignItemS();
			Envelope ev = new Envelope(itemC,"Active the campign plzz");
			sendToServer(ev);
		}
		
	}

}
